package com.tian.core.thread;


import com.tian.core.base.model.BaseUser;

/**
 * @author Wenqiang Yang
 * @date 2018/01/12
 */
public class UserThreadLocal {

    private static ThreadLocal<BaseUser> threadLocal = new ThreadLocal<>();
    private volatile static UserThreadLocal userThreadLocal;


    public static UserThreadLocal getInstance(){
        UserThreadLocal result = userThreadLocal;
        if(null == result) {
            synchronized (UserThreadLocal.class){
                result = userThreadLocal;
                if(null == result) {
                    userThreadLocal = new UserThreadLocal();
                }
            }
        }
        return result;
    }
    private UserThreadLocal(){}

    public void setUser(BaseUser baseUser){
        threadLocal.set(baseUser);
    }

    public BaseUser getUser() {
        return threadLocal.get();
    }
    public void removeUser(){
        threadLocal.remove();
    }
}
